<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        #smallImg {
            width: 300px;
            height: 300px;
            background-image: url(./lou.jpg);
            background-size: cover;
        }
        #smallDiv {
            width: 100px;
            height: 100px;
            background-color: rgba(255, 0, 0, .2); 
            display: none;
            position: absolute;
        }

        #bigDiv {
            width: 300px;
            height: 300px;
            /* border: 1px solid red; */
            position: absolute;
            left: 300px;
            top: 0px;
            overflow: hidden;
            display: none;
        }

        #bigImg {
            width: 900px;
            height: 900px;
            position: absolute;
        }
    </style>
</head>

<body>
    
    <div class="fang">
        <div id="smallImg">
            <div id="smallDiv"></div>
        </div>

        <div id="bigDiv">
            <img src="./lou.jpg" alt="" id="bigImg">
        </div>
    </div>


    <script>
        $('#smallImg').mousemove((event)=>{
            let [X, Y] = [event.originalEvent.clientX, event.originalEvent.clientY];
            X -= 50;
            Y -= 50;
            if(X < 0)
                X = 0;
            if(X > 200)
                X = 200;
            if(Y < 0)
                Y = 0;
            if(Y > 200)
                Y = 200;
            $('#smallDiv').css({'left': X+'px', 'top': Y+'px'});
            // 放大三倍
            $('#bigImg').css({'left': -3*X+'px', 'top': -3*Y+'px'});
        })
        $('#smallImg').mouseover(()=>{
            $('#smallDiv').css({"display": "block"});
            $('#bigDiv').css("display", "block");
        })
        $('#smallImg').mouseout(()=>{
            $('#smallDiv').css("display", "none");
            $('#bigDiv').css("display", "none");
        })

    </script>

</body>

</html>